<?php

namespace app\admin\controller;

use app\common\service\BalanceService;
use app\common\service\InvestService;
use think\Db;

class User extends Common {

	public function index() {
		$pid = request()->param('pid');
		$uid = request()->param('uid');
		$jdid = request()->param('jdid');
		if (!empty($pid) || !empty($uid) || !empty($jdid)) {
			if (!empty($pid)) {
				$this->assign('type', 'pid');
				$this->assign('id', $pid);
			}
			if (!empty($jdid)) {
				$this->assign('type', 'jdid');
				$this->assign('id', $jdid);
			}
			if (!empty($uid)) {
				$this->assign('type', 'uid');
				$this->assign('id', $uid);
			}
		} else {
			$this->assign('type', '0');
			$this->assign('id', 0);
		}
		return $this->fetch();
	}

	public function dataList() {
		$limit = request()->param('limit') ?: 20;
		$page = request()->param('page');
		$username = request()->param('username');
		$identity_status = request()->param('identity_status');
		$status = request()->param('status');
		$phone = request()->param('phone');
		$quhao = request()->param('quhao');

		$id = request()->param('id');
		$bid = request()->param('bid');
		$level = request()->param('level');
		$robot_level = request()->param('robot_level');
		$address = request()->param('address');
		$uuid = request()->param('uuid');
		$uid = request()->param('uid') ?: '';
		$pid = request()->param('pid') ?: '';
		$ppid = request()->param('ppid') ?: '';
		$jdid = request()->param('jdid') ?: '';
		$ye1 = request()->param('ye1') ?: '';
		$ye2 = request()->param('ye2') ?: '';
		$start_time = request()->param('start_time');
		$end_time   = request()->param('end_time');
		$where = '1=1';
		if ($username != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			$where .= ' and u.username like \'%'.$username.'%\'';
		}
		if ($identity_status != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			$where .= ' and u.identity_status='.$identity_status;
		}
		if ($status != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			$where .= ' and u.status='.$status;
		}
		if ($quhao != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			$where .= ' and u.quhao='.$quhao;
		}
		if ($level != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			$where .= ' and u.level='.$level;
		}
		if ($robot_level != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			$where .= ' and u.robot_level='.$robot_level;
		}
		if ($ye1 != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			$where .= ' and b.balance>='.$ye1;
		}
		if ($ye2 != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			$where .= ' and b.balance<='.$ye2;
		}
		if ($id != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			if (!in_array($id, $this->data_uids_arr)) {
				return $this->tableData([]);
			}
			$where .= ' and u.id='.$id;
		} else {
			if ($this->data_uids_string) {
				$where .= ' and u.id in ('.$this->data_uids_string.')';
			}
		}
		if($uuid != '') {
			if (!in_array($uuid, $this->data_uids_arr)) {
				return $this->tableData([]);
				// return ['code' => 1, 'msg' => '权限不足'];
			} else {

				$data_uids_arr = Db::table('tp_user_team')->where('uid',$uuid)->column('x_uid');
				$data_uids_arr[] = $uuid;
				$daaaa = implode($data_uids_arr, ',');
				$where .= ' and u.id in ('.$daaaa.')';
			}
		}
		if ($bid != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			// $id = $id/99;
			$where .= ' and u.bourse_uid='.$bid;
		}
		if ($ppid != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			// $id = $id/99;
			$where .= ' and u.pid='.$ppid;
		}
		if($address != ''){
			$id = Db::table('tp_user_wallet_address')->where('address',$address)->value('uid')?:0;
			$uid = '';
			$pid = '';
			$jdid = '';
			$where .= ' and u.id='.$id;
		}
		if ($phone != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			$where .= ' and u.phone='.$phone;
		}
		if ($uid != '') {
			$where .= ' and u.pid='.$uid;
		}
		if ($pid != '') {
			$where .= ' and u.id='.$pid;
		}
		if ($jdid != '') {
			$where .= ' and u.jdid='.$jdid;
		}
		 if($start_time != '') {
            $where .= ' and u.reg_date>="'.$start_time.'"';
        }
		if($end_time != '') {
            $where .= ' and u.reg_date<="'.$end_time.'"';
        }
		$data = Db::table('tp_user')
				->alias('u')
				->join('tp_user u1', 'u1.id = u.pid', 'LEFT')
				->join('tp_user u2', 'u2.id = u.jdid', 'LEFT')
				->join('tp_user_balance b', 'u.id = b.uid and b.wid=1', 'LEFT')
				->where($where)
				->field('u.*,u1.username v_name,u2.username jd_name,u1.id invite_uid,b.balance')
				->order("id desc")
				->paginate($limit);
		$data = $data->toArray();
		if(empty($data['data'])){
			$data['data']  = Db::table('tp_user')
									->alias('u')
									->join('tp_user u1', 'u1.id = u.pid', 'LEFT')
									->join('tp_user u2', 'u2.id = u.jdid', 'LEFT')
									->join('tp_user_balance b', 'u.id = b.uid and b.wid=1', 'LEFT')
									->where($where)
									->field('u.*,u1.username v_name,u2.username jd_name,u1.id invite_uid,b.balance')
									->order("id asc")
									->page(1)
									->select();
		}
		
		foreach ($data['data'] as $key => $val) {
			$uid = $val['id'];
			//邀请人数
			$data['data'][$key]['zk'] = Db::table('tp_user')->where('pid', $val['id'])->count();
			$record = Db::table('tp_invest_record')->where('uid', $val['id'])->order('id desc')->find();
			$data['data'][$key]['robot_name'] = $record['name'];
			$data['data'][$key]['level_name'] = Db::table('tp_invest_level_config')->where('level',$val['level'])->value('name');
			$data['data'][$key]['robot_status'] = $record['status'];
			//头像
			// $data['data'][$key]['avatar'] = $this->imageUrl($val['avatar']);
		}
		return $this->tableData($data);
	}

	public function excel() {
		$limit = request()->param('limit') ?: 20;
		$page = request()->param('page');
		$username = request()->param('username');
		$identity_status = request()->param('identity_status');
		$status = request()->param('status');
		$phone = request()->param('phone');
		$quhao = request()->param('quhao');

		$id = request()->param('id');
		$bid = request()->param('bid');
		$level = request()->param('level');
		$robot_level = request()->param('robot_level');
		$address = request()->param('address');
		$uid = request()->param('uid') ?: '';
		$pid = request()->param('pid') ?: '';
		$jdid = request()->param('jdid') ?: '';
		$start_time = request()->param('start_time');
		$end_time   = request()->param('end_time');
		$where = '1=1';
		if ($username != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			$where .= ' and u.username like \'%'.$username.'%\'';
		}
		if ($identity_status != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			$where .= ' and u.identity_status='.$identity_status;
		}
		if ($status != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			$where .= ' and u.status='.$status;
		}
		if ($quhao != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			$where .= ' and u.quhao='.$quhao;
		}
		if ($level != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			$where .= ' and u.level='.$level;
		}
		if ($robot_level != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			$where .= ' and u.robot_level='.$robot_level;
		}
		if ($id != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			if (!in_array($id, $this->data_uids_arr)) {
				return $this->tableData([]);
			}
			$where .= ' and u.id='.$id;
		} else {
			if ($this->data_uids_string) {
				$where .= ' and u.id in ('.$this->data_uids_string.')';
			}
		}
		if ($bid != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			// $id = $id/99;
			$where .= ' and u.bourse_uid='.$bid;
		}
		if($address != ''){
			$id = Db::table('tp_user_wallet_address')->where('address',$address)->value('uid')?:0;
			$uid = '';
			$pid = '';
			$jdid = '';
			$where .= ' and u.id='.$id;
		}
		if ($phone != '') {
			$uid = '';
			$pid = '';
			$jdid = '';
			$where .= ' and u.phone='.$phone;
		}
		if ($uid != '') {
			$where .= ' and u.pid='.$uid;
		}
		if ($pid != '') {
			$where .= ' and u.id='.$pid;
		}
		if ($jdid != '') {
			$where .= ' and u.jdid='.$jdid;
		}
		 if($start_time != '') {
            $where .= ' and u.reg_date>="'.$start_time.'"';
        }
		if($end_time != '') {
            $where .= ' and u.reg_date<="'.$end_time.'"';
        }
		$data = Db::table('tp_user')
				->alias('u')
				->join('tp_user u1', 'u1.id = u.pid', 'LEFT')
				->join('tp_user u2', 'u2.id = u.jdid', 'LEFT')
				->join('tp_invest_level_config c1', 'u.level = c1.level', 'LEFT')
				->join('tp_invest_config c2', 'u.robot_level = c2.id', 'LEFT')
				->join('tp_user_balance b', 'u.id = b.uid and b.wid=1', 'LEFT')
				->where($where)
				->field('u.id,u.phone,u.reg_date,c1.name,c2.name robot_name,b.balance')
				->order("id desc")
				->select();
		// foreach ($data as $key => $val) {
		// 	//邀请人数
		// 	$data[$key]['zk'] = Db::table('tp_user')->where('pid', $val['id'])->count();
		// 	if (strpos($val['address'],'0x') === false) {
		// 		$data[$key]['ye'] = $this->getBalance($val['address'],2)?:0;
		// 	} else {
		// 		$data[$key]['ye'] = $this->getBalance($val['address'],1)?:0;
		// 	}
		// }
		return exportExcel(['用户编号', '电话', '注册时间', '用户等级', '智能云等级','USDT余额'], $data);
	}

	//编辑用户
	public function editUser() {
		if (request()->method() == 'POST') {
			if (!in_array($this->admin_info['level'], [1,2])) {
				return ['code' => 1, 'msg' => '权限不足'];
			}
			$data = [];
			$data['id'] = request()->param('id');
			$data['username'] = request()->param('username');
			$data['phone'] = request()->param('phone');
			// $data['mail'] = request()->param('mail');
			$password = request()->param('password');

			$data['status'] = request()->param('status');
			$data['out_status'] = request()->param('out_status');
			$data['static_profit_status'] = request()->param('static_profit_status');
			$data['invite_profit_status'] = request()->param('invite_profit_status');
			$data['team_profit_status'] = request()->param('team_profit_status');
			$level = request()->param('level');

			$paypass = request()->param('paypass');
			if (!empty($password)) {
				$data['password'] = md5($password);
			}
			if (!empty($paypass)) {
				$data['paypass'] = $paypass;
			}
			$has = Db::table('tp_user')->where('id', $data['id'])->find();
			if ($has['level'] != $level) {
				$data['level'] = $level;
				$data['vip_update_date'] = date('Y-m-d H:i:s');
			}
			if ($has['status'] == 1 && $data['status'] == 0) {
				$token = Db::table('tp_token')->where('uid', $data['id'])->find();
				if (empty($token)) {
					// $res2 = 1;
				} else {
					Db::table('tp_token')->where('uid', $data['id'])->delete();
				}
			}
			$res = Db::table('tp_user')->where('id', $data['id'])->update($data);
			if ($res) {
				return ['code' => 0, 'msg' => 'success'];
			} else {
				return ['code' => 1, 'msg' => '更新失败'];
			}
		} else {
			$id = request()->param('id');
			$data = Db::table('tp_user')
					->where('id', $id)
					->find();
			$level = Db::table('tp_invest_level_config')
					->group('level')
					->select();
			if (!in_array($this->admin_info['level'], [1,2])) {
				$data['paypass'] = '';
			}
			$this->assign('level', $level);
			$this->assign('data', $data);
			return $this->fetch();
		}
	}






///////////////////////////////////////////
	//团队结构
	public function team() {
		$username = request()->param('username')?:'';
		$this->assign('username', $username);
		return $this->fetch();
	}

	public function teamdata() {
		// $uid = request()->param('uid');
		// if($uid){
		// 	// $data = 
		// } else {
			$data = Db::table('tp_user')->field("id,pid,jdid,username")->select();
		// }
		return json($data);
	}


/////////////////////////////////////////

	/*
	  支付信息
	 */

	public function payInfo() {
		$uid = request()->param('id');
		$data = Db::table('tp_pay_info')->where('uid', $uid)->find();
		if(empty($data)){

		} else {
			$data['weixin_code'] = $this->imageUrl($data['weixin_code']);
			$data['alipay_code'] = $this->imageUrl($data['alipay_code']);
		}

		$this->assign('uid', $uid);
		$this->assign('data', $data);
		return $this->fetch();
	}

	/*
	  认证信息
	 */

	public function verifyInfo() {
		$uid = request()->param('id');
		$data = Db::table('tp_user')
				->where('id', $uid)
				->field('id,real_name,idcard_no,idcard_front,idcard_back,identity_status')
				->find();
		switch ($data['identity_status']) {
			case '0':
				$data['remark'] = '未认证';
				break;
			case '1':
				$data['remark'] = '待审核';
				break;
			case '2':
				$data['remark'] = '已认证';
				break;
			case '3':
				$data['remark'] = '认证失败';
				break;
			default:
# code...
				break;
		}
		$data['idcard_front'] = $this->imageUrl($data['idcard_front']);
		$data['idcard_back'] = $this->imageUrl($data['idcard_back']);
		$this->assign('data', $data);
		return $this->fetch();
	}

/////////////////////////////////////////////
	/*
	  冻结/解冻
	 */

	public function freeze() {
		$uid = request()->param('id');
		$info = Db::table('tp_user')->where('id', $uid)->find();
		if ($info['status'] == 1) {
			Db::startTrans();
			$res1 = Db::table('tp_user')->where('id', $uid)->update([
				'status' => 0,
			]);
			$token = Db::table('tp_token')->where('uid', $uid)->find();
			if (empty($token)) {
				$res2 = 1;
			} else {
				$res2 = Db::table('tp_token')->where('uid', $uid)->delete();
			}
			if ($res1 && $res2) {
				$res = 1;
				Db::commit();
			} else {
				$res = 0;
				Db::rollback();
			}
		} else {
			$res = Db::table('tp_user')->where('id', $uid)->update([
				'status' => 1,
			]);
		}
		if ($res) {
			return ['code' => 0, 'msg' => 'success'];
		} else {
			return ['code' => 1, 'msg' => '操作失败'];
		}
	}


	public function delUser(){
		$uid = request()->param('id');
		$info = Db::table('tp_user')->where('id', $uid)->find();
		if (!$info) {
			return ['code' => 1, 'msg' => '用户不存在'];
		}

		$x = Db::table('tp_user')->where('pid',$uid)->find();
		if ($x) {
			return ['code' => 1, 'msg' => '存在下级，不可删除'];
		}

		$res = Db::table('tp_user')->where('id', $uid)->delete();
		if ($res) {
			return ['code' => 0, 'msg' => 'success'];
		} else {
			return ['code' => 1, 'msg' => '操作失败'];
		}
	}
////////////////////////////////////////////////////////////////////////
	/*
	  拨币F
	 */

	public function bb() {
		if (request()->method() == 'POST') {
			if ($this->admin_info['level'] != 1) {
				return ['code' => 1, 'msg' => '权限不足'];
			}
			$data = [];
// $password = request()->param('password');
// if($password != 'nc666'){
// 	return ['code'=>0,'msg'=>'拨币密码错误'];
// }
			// $id = request()->param('id');
			$wid = request()->param('wid');
			$uid = request()->param('uid');
			$field = request()->param('field');
			$amount = request()->param('amount');
			$token = request()->param('token');
			if ($token != session('bb_token')) {
				return ['code' => 1, 'msg' => '请勿重复提交'];
			}

			$res = 1;
			if ($field == 'change') {
				$res = BalanceService::updateBalance($uid, $wid, $amount, '赠送', 11, 0);
			} 

			if ($res) {
				return ['code' => 0, 'msg' => 'success'];
			} else {
				return ['code' => 1, 'msg' => '转账失败'];
			}
		} else {
			$uid = request()->param('id');
			$this->assign('uid', $uid);
			$token = MD5(time());
			session('bb_token', $token);
			$this->assign('token', $token);
			return $this->fetch();
		}
	}

	public function balancelist() {
		$uid = request()->param('uid');
		$limit = request()->param('limit') ?: 20;
		$coin = Db::table('tp_coin_wallet')->where('status', 1)->select();
		$data = [];
		$data['data'] = [];
		$username = Db::table('tp_user')->where('id', $uid)->value('username');
		foreach ($coin as $key => $val) {
			$info = [];
			$user_balance = Db::table('tp_user_balance')->where('uid', $uid)->where('wid', $val['id'])->field('id,balance')->find();
			$info['id'] = $user_balance['id'];
			$info['balance'] = $user_balance['balance'] ?: 0;
			$info['wallet_name'] = $val['name'];
			$info['wid'] = $val['id'];
			$info['username'] = $username;
			$info['address'] = Db::table('tp_user_wallet_address')->where('uid',$uid)->where('wid',$val['id'])->value('address');
			$data['data'][] = $info;
		}
		$data['count'] = count($data['data']);
		// $data = Db::table('tp_coin')
		// 			->alias('c')
		// 			->join('user_balance u','c.id = u.cid','RIGHT')
		// 			->join('user s','s.id = u.uid','RIGHT')
		// 			->where('u.uid',$uid)
		// 			->where('c.status',1)
		// 			->field('u.*,c.name coin_name,s.username')
		// 			->paginate($limit);
		// $data = $data->toArray();

		return ['code' => 0, 'msg' => '', 'count' => $data['count'], 'data' => $data['data']];
	}

/////////////////////////////////////////////////////////////////////
	//额外的

	public function tdyj() {
		if (request()->method() == 'POST') {
			$uid = request()->param('uid');
		
			if ($res) {
				return ['code' => 0, 'msg' => 'success'];
			} else {
				return ['code' => 1, 'msg' => '操作失败'];
			}
		} else {
			$uid = request()->param('uid');
			//total
			$xids = Db::table('tp_user_team')->where('uid',$uid)->column('x_uid');
			$total = Db::table('tp_invest_record')->where('uid','in',$xids)->where('is_complete',0)->sum('amount');
			$sef   = Db::table('tp_invest_record')->where('uid',$uid)->where('is_complete',0)->sum('amount');
			$this->assign('total', $total);
			$this->assign('sef', $sef);
			$this->assign('uid', $uid);
			return $this->fetch();
		}
	}

/////////////////////////////////////////////////////////////////////
///
	private function getAllXid($uid) {
		$data = [];
		$uids = [];
		$i = 0;
		while ($uid) {
			$uid = Db::table('tp_user')->where('pid', 'in', $uid)->column('id');
			if ($uid) {
				$uids = array_merge($uids, $uid);
				$i += 1;
			}
		}
		$data['uids'] = $uids;
		$data['depth'] = $i;
		return $uids;
	}

	protected function getAssigPid($uid, $depth) {
		$uids = [];
		for ($i = 1; $i < $depth + 1; $i++) {
			$uid = Db::table('tp_user')->where('pid', 'in', $uid)->column('id');
			if ($uid) {
				$uids = array_merge($uid, $uids);
			} else {
				break;
			}
		}
		return $uids;
	}
public function balance() {
		$wallet = Db::table('tp_coin_wallet')->where('status',1)->select();
		$this->assign('wallet',$wallet);
		return $this->fetch();
	}
	public function balanceData() {
		$limit = request()->param('limit') ?: 20;
		$page = request()->param('page');
		$uid   = request()->param('uid');
		$wid   = request()->param('wid');
		$where      = '1=1';

        // if($uid != '') {
        //     $where .= ' and b.uid='.$uid;
        // }
        if($uid != '') {
			if (!in_array($uid, $this->data_uids_arr)) {
				return $this->tableData([]);
			}
			$where .= ' and b.uid='.$uid;
		} else {
			if ($this->data_uids_string) {
				$where .= ' and b.uid in ('.$this->data_uids_string.')';
			}
		}
        if($wid != '') {
            $where .= ' and b.wid='.$wid;
        }

		$data = Db::table('tp_user_balance')
				->alias('b')
				->join('tp_coin_wallet w', 'w.id = b.wid', 'LEFT')
				->join('tp_user u', 'u.id = b.uid', 'LEFT')
				->where($where)
				->field('b.*,w.name wallet_name,u.username')
				->order("id asc")
				->paginate($limit);
		$data = $data->toArray();
		if(empty($data['data'])){
			$data['data']  = Db::table('tp_user_balance')
									->alias('b')
									->join('tp_coin_wallet w', 'w.id = b.wid', 'LEFT')
									->join('tp_user u', 'u.id = b.uid', 'LEFT')
									->where($where)
									->field('b.*,w.name wallet_name,u.username')
									->order("id asc")
									->page(1)
									->select();
		}
	
		return $this->tableData($data);
	}

	public function getBalance($address='',$type=1){
		if ($type == 1) {
			//trx
			$balance =  curl("https://api.trongrid.io/v1/accounts/".$address."?contract_address=TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t");
			// var_dump($address);die();
			$balance = json_decode($balance,1);
			$ye = 0;
			if(isset($balance['data'][0]['trc20'])){
			    foreach ($balance['data'][0]['trc20'] as $k=>$v){
			        if(isset($v['TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'])){
			            $ye = $v['TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t']/1000000;
			        }
			    }
			    
			 //   echo $address.'--'.$ye."\n";
			    if($ye<=0) {
			        return 0;
			    }
			    //判断交易
			    // $timestamp = (time()-3600*12-60)*1000;
			    // $data = curl("https://api.trongrid.io/v1/accounts/".$address."/transactions/trc20?only_confirmed=true&only_from=true&min_timestamp=".$timestamp."&contract_address=TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t&order_by=block_timestamp,desc");
			    // $data = json_decode($data,1);
			    // if($data['data']){
			    //     return 0;
			    // } else {
			        return $ye;
			    // }
			} else {
			    return 0;
			}
		} elseif ($type == 2) {
			$balance =  curl('https://api.etherscan.io/api?module=account&action=tokenbalance&address='.$address.'&contractaddress=0xdac17f958d2ee523a2206206994597c13d831ec7&apikey=IYR3CPUCR15QED78SK11W573QS8DA2JTMI');
			// var_dump($address);die();
			$ye = json_decode($balance,1)['result']/1000000;
// 			echo $address.'--'.$ye."\n";
			if($ye <= 0) {
			    return 0;
			}
            //判断交易
		    // $timestamp = time()-3600*12-60;
		    // $data = curl('https://api.etherscan.io/api?module=account&action=tokentx&sort=desc&address='.$address.'&contractaddress=0xdac17f958d2ee523a2206206994597c13d831ec7&apikey=D1XFTT7JYI9NMBCI3KGJH9SKVWWIGN34B2');
		    // $data = json_decode($data,1);
		    // if($data['status']==0 || empty($data['result'])){
		    //     return $ye;
		    // }
		    // foreach ($data['result'] as $val) {
		    //     if($val['timeStamp']<$timestamp){
		    //         break;
		    //     }
		    //     if(strtolower($val['from']) == strtolower($address)){
		    //         return 0;
		    //     }
		    // }
		    return $ye;
		} elseif ($type == 3) {
            $balance = curl('https://api.bscscan.com/api?module=account&action=tokenbalance&address='.$address.'&tag=latest&contractaddress=0xe9e7cea3dedca5984780bafc599bd69add087d56&apikey=3U95STBVNME1UYFGWYY2YWZXQYWUA22K1W');
			$ye = json_decode($balance,1)['result']/1000000000000000000;
// 			echo $address.'--'.$ye."\n";
			if($ye <= 0) {
			    return 0;
			}
            //判断交易
		    // $timestamp = time()-3600*12-60;
		    // $data = curl('https://api.bscscan.com/api?module=account&action=tokentx&sort=desc&address='.$address.'&contractaddress=0xe9e7cea3dedca5984780bafc599bd69add087d56&apikey=3U95STBVNME1UYFGWYY2YWZXQYWUA22K1W');
		    // $data = json_decode($data,1);
		    // if($data['status']==0 || empty($data['result'])){
		    //     return $ye;
		    // }
		    // foreach ($data['result'] as $val) {
		    //     if($val['timeStamp']<$timestamp){
		    //         break;
		    //     }
		    //     if(strtolower($val['from']) == strtolower($address)){
		    //         return 0;
		    //     }
		    // }
		    return $ye;
		}
	}
	
	 public function getOutRecord(){
    	$data = Db::table('tp_out_record')->where('status',0)->order('id desc')->find();
    	if($data){
    		$res = Db::table('tp_out_record')->where('id',$data['id'])->update(['status'=>1]);
    		if ($res) {
    			$this->retData(0,'success',$data);
    		} else {
    			$this->retData(1,'success',[]);
    		}
    	} else {
    		$this->retData(1,'success',[]);
    	}
    }
}
